

package controllerLayer;
import modelLayer.*;
import DBLayer.*;

import java.util.ArrayList;

public class CtrCustomer {
   
	DBCustomer dbCus = new DBCustomer();
	
    /** Creates a new instance of CtrCustomer */
    public CtrCustomer() {
        
    }

    public Customer findCustomer(String phoneNo)
    {
        return dbCus.findCustomer(phoneNo, true);
    }
    public boolean registerNewCustomer(String _fname, String _lname, String _customerAddress, String _zipCode, String _country, String _phoneNo, String _email, String _customerType)
    {
    	boolean succes = false;
    	
    	Customer temCustomer = new Customer(_fname, _lname, _customerAddress, _zipCode, _country, _phoneNo, _email, _customerType);
    	
    	dbCus.insertCostumer(temCustomer); 
    	if(findCustomer(_phoneNo) != null)
    	{
    		succes = true;
    	}
    	return succes;
    }
    
    public boolean updateCustomer(String _fname, String _lname, String _customerAddress, String _zipCode, String _country, String _phoneNo, String _email, String _customerType)
    {
    	boolean succes = false;
    	
    	Customer temCustomer = findCustomer(_phoneNo);
    	
    	temCustomer.setFname(_fname);
    	temCustomer.setLname(_lname);
    	temCustomer.setCustomerAddress(_customerAddress);
    	temCustomer.setZipCode(_zipCode);
    	temCustomer.setCountry(_country);
    	temCustomer.setPhoneNo(_phoneNo);
    	temCustomer.setEmail(_email);
    	temCustomer.setCustomerType(_customerType);
    	
    	DBCustomer dbCus = new DBCustomer();
    	dbCus.updateCustomer(temCustomer);
    	
    	if(findCustomer(_phoneNo).getCustomerAddress().equalsIgnoreCase(_customerAddress));
    	{
    		succes = true;
    	}
    	
    	return succes;
    }
    //did not work
    /*public ArrayList<Customer> listAllCustomer()
    {
    	ArrayList<Customer>listAllCustomer;
    	listAllCustomer = dbCus.listAllCustomer();
    	return listAllCustomer;
    }*/
    
    
}
